package com.lhkj.ct.meta.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lhkj.ct.base.model.dto.PageQuery;
import com.lhkj.ct.base.mybatis.extension.service.impl.IServiceImpl;
import com.lhkj.ct.meta.admin.mapper.LoginLogMapper;
import com.lhkj.ct.meta.admin.model.entity.TblLoginLog;
import com.lhkj.ct.meta.admin.service.LoginLogService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 登录日志 服务实现类
 * </p>
 *
 * @author jobob
 * @since 2023-09-20
 */
@Service
public class LoginLogServiceImpl extends IServiceImpl<LoginLogMapper, TblLoginLog> implements LoginLogService {

    @Override
    public IPage<TblLoginLog> selectLoginLogPage(TblLoginLog loginLog, PageQuery pageQuery) {
        LambdaQueryWrapper<TblLoginLog> queryWrapper = new LambdaQueryWrapper<TblLoginLog>()
                .like(StringUtils.isNotBlank(loginLog.getIpaddr()), TblLoginLog::getIpaddr, loginLog.getIpaddr())
                .like(StringUtils.isNotBlank(loginLog.getUserName()), TblLoginLog::getUserName, loginLog.getUserName())
                .eq(null != loginLog.getStatus(), TblLoginLog::getStatus, loginLog.getStatus());
        if (null != pageQuery.getBeginTime() && null != pageQuery.getEndTime()) {
            queryWrapper.between(TblLoginLog::getLoginTime, pageQuery.getBeginTime(), pageQuery.getEndTime());
        }
        return getBaseMapper().selectPage(generatePage(pageQuery), queryWrapper);
    }

    @Override
    public void clear() {
        getBaseMapper().clear();
    }
}
